home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1998 November / Cd users extra 14.iso / prog / inst / mailc / mailer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-14  |  2.2 KB  |  75 lines

  1. /*
  2. **  MAILER.C [edit EMAIL.H before compiling]
  3. **
  4. **  This program emails a specified message.
  5. */
  6.  
  7. #include <windows.h>
  8. #include <stdio.h>
  9. #include "see.h"
  10. #include "email.h"
  11.  
  12. #define QUOTE 0x22
  13.  
  14. static char Buffer[512];
  15.  
  16. /* display error message */
  17.  
  18. static void ErrorExit(int Code, LPSTR Msg)
  19. {printf("ERROR: ");
  20.  if(Msg) printf("%s\n",Msg);
  21.  if(Code)
  22.    {seeErrorText(Code,(LPSTR)Buffer,50);
  23.     printf("%s\n",(LPSTR)Buffer);
  24.     exit(1);
  25.    }
  26. }
  27.  
  28. void main(int argc, char *argv[])
  29. {int Code; 
  30.  if(argc!=4)
  31.    {printf("Usage: MAILER email-text subject <email-addr>\n");
  32.     printf("   eg: MAILER %c@test.mai%c %cThis is a test%c %c<mike@marshallsoft.com>%c\n",
  33.                    QUOTE,QUOTE,QUOTE,QUOTE,QUOTE,QUOTE);
  34.     exit(1);
  35.    } 
  36.  
  37.  /* display parameters */
  38.  printf("Server : %s\n",(LPSTR)SMTP_HOST_NAME);
  39.  printf("  From : %s\n",(LPSTR)YOUR_EMAIL_ADDR);
  40.  if(*argv[1]=='@') printf("  File : %s\n", argv[1]);
  41.  else printf("  Text : %c%s%c\n", QUOTE,argv[1],QUOTE);
  42.  printf("  Subj : %s\n", argv[2]);
  43.  printf("    To : %s\n", argv[3]);
  44.  
  45.  /* check format of email addresses */
  46.  Code = seeVerifyFormat((LPSTR)argv[3]);
  47.  if(Code<0) ErrorExit(Code,(LPSTR)argv[3]);
  48.  Code = seeVerifyFormat(YOUR_EMAIL_ADDR);
  49.  if(Code<0) ErrorExit(Code,(LPSTR)YOUR_EMAIL_ADDR);
  50.  
  51.  /* define diagnostics log file */
  52.  seeStringParam(SEE_LOG_FILE, (LPSTR)"mailer.log"); 
  53.  
  54.  /* connect to SMTP server */
  55.  puts("Connecting...");
  56.  Code = seeSmtpConnect(
  57.     (LPSTR)SMTP_HOST_NAME,           /* SMTP server */
  58.     (LPSTR)YOUR_EMAIL_ADDR,          /* return email address */ 
  59.     (LPSTR)NULL);                    /* Reply-To header */
  60.  if(Code<0)ErrorExit(Code,(LPSTR)"Connect:"); 
  61.  /* send email */
  62.  puts("Sending mail...");
  63.  Code = seeSendEmail(
  64.     (LPSTR)argv[3],                  /* To list */
  65.     (LPSTR)NULL,                     /* CC list */
  66.     (LPSTR)NULL,                     /* BCC list */
  67.     (LPSTR)argv[2],                  /* subject */
  68.     (LPSTR)argv[1],                  /* message text */
  69.     (LPSTR)NULL);                    /* MIME attachment */                
  70.  if(Code<0) ErrorExit(Code,(LPSTR)"Sending email:"); 
  71.  Code = seeClose();
  72. } /* end main */
  73.  
  74.  
  75.